package br.com.vti.sisp_sicrim.model.entity.converter;

import java.util.ResourceBundle;

import javax.enterprise.inject.Specializes;

import br.com.caelum.vraptor.Convert;
import br.com.caelum.vraptor.Converter;
import br.com.caelum.vraptor.ioc.ApplicationScoped;
import br.com.crud4j.core.util.Reflection;

/**
 *
 * @author ednardomatos
 */
@Specializes
@ApplicationScoped
@Convert(Integer.class)
public class IntegerConverter implements Converter<Integer> {

	@Override
	public Integer convert(String value, Class<? extends Integer> type, ResourceBundle bundle) {
		if(!Reflection.isNullOrEmpty(value)) {
			value = value.replaceAll("[^\\d]", "");
			return Integer.parseInt(value);
		}
		return null;
	}

}